package com.xiaoshu.security.impl;

import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang3.StringUtils;

import com.xiaoshu.security.TokenManager;

/**
 * 进行Token的获取和管理
 * @author Administrator
 *
 */
public class DefaultTokenManager implements TokenManager{

	private  ConcurrentHashMap<String, Object> tokenMaps = new ConcurrentHashMap<String, Object>();
	
	@Override
	public String createToken(String userName) {
		String token = UUID.randomUUID().toString().replace("-", "");
		System.out.println("generate token is：" + token);
		tokenMaps.put(token, userName);
		return token;
	}
	
	@Override
	public boolean checkToken(String token) {
		System.out.println("token is :" + token);
		if(StringUtils.isNotEmpty(token) && tokenMaps.containsKey(token)){
			return true;
		}
		return false;
	}

}
